using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI.EventBroker;
using NetRosApp.Infrastructure.Interface.Constants;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI.WinForms;
using NetRosApp.Infrastructure.Interface.Base.BaseViews;
using System.Windows.Forms;

namespace NetRosApp.Infrastructure.Interface.Base
{
    public class EventsZaPrikaz
    {
        private WorkItem _WorkItem;

        [InjectionConstructor]
        public EventsZaPrikaz([ServiceDependency] WorkItem WorkItem)
        {
            _WorkItem = WorkItem;
        }

        //[EventSubscription(EventTopicNames.ShowArtiklTrazisKategorijom, ThreadOption.UserInterface)]
        //public void OnShowArtiklTrazi(object sender, TraziEventArgs<EventArgs<Artikl,int?>> eventArgs)
        //{//TODO: Add your code here (object eValue, DokumentStavka _dokumentStavka)

        //    ArtiklTrazi tmp = new ArtiklTrazi(sender, eventArgs.Entity.Data,eventArgs.Container,eventArgs.Entity.Data1);

        //    _WorkItem.SmartParts.Add(tmp);

        //    WindowSmartPartInfo wspi = new WindowSmartPartInfo();
        //    wspi.Modal = true;

        //    _WorkItem.Workspaces[Constants.WorkspaceNames.ModalWindows].Show(tmp, wspi);

        //}


        [EventSubscription(EventTopicNames.OpenCreateView, ThreadOption.UserInterface)]
        public void OnOpenCreateView(object sender, EventArgs<object, object, object, object, WorkItem> eventArgs)
        {
            Cursor.Current = Cursors.WaitCursor;
            //BaseEditWorkItem tmpitm = _WorkItem.WorkItems.Get((eventArgs.Data as Type).ToString()) as BaseEditWorkItem;
            BaseEditWorkItem tmpitm;
             WorkItem uitem = _WorkItem;
            if (uitem != null)
            {
             uitem = eventArgs.Data4 as WorkItem;
            }


            if (eventArgs.Data3 != null)
            {
                eventArgs.Data4.EventTopics[EventTopicNames.EntityItemChanged].Fire(this, new EventArgs<object, string>(eventArgs.Data1, "Entity"), eventArgs.Data4, PublicationScope.WorkItem);
            }
            else
            {

                //if (tmpitm == null)
                //{
                tmpitm = new BaseEditWorkItem((eventArgs.Data as Type));
                uitem.WorkItems.Add(tmpitm);
                //      _WorkItem.WorkItems.Add(tmpitm, (eventArgs.Data as Type).ToString());
                //}
                tmpitm.Start(eventArgs.Data1, eventArgs.Data2);
            }
            Cursor.Current = Cursors.Default;
        }

        [EventSubscription(EventTopicNames.OpenCreateViewModal, ThreadOption.UserInterface)]
        public void OnOpenCreateViewModal(object sender, EventArgs<WorkItem, object, object, WindowSmartPartInfo, object> eventArgs)
        {
            Cursor.Current = Cursors.WaitCursor;
            //     BaseEditWorkItem tmpitm = _WorkItem.WorkItems.Get((eventArgs.Data as Type).ToString()) as BaseEditWorkItem;

            WorkItem olditem = eventArgs.Data as WorkItem;

            BaseEditWorkItem tmpitm = new BaseEditWorkItem((eventArgs.Data1 as Type));

            olditem.WorkItems.Add(tmpitm);

            tmpitm.StartModal(eventArgs.Data2, eventArgs.Data3, eventArgs.Data4);
            Cursor.Current = Cursors.Default;
        }

    }
}
